<?php namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

abstract class Request extends FormRequest
{

    //
    public function response(array $errors)
    {
        if ($this->segment(1) == 'admin' && $this->ajax()) {
            $str = '';
            foreach ($errors as $key => $item) {
                $str .= $key . ':' . implode(',', $item) . '<br>';
            }
            return response()->json([
                'statusCode' => '300',
                'message' => $str
            ]);
        }
        if ($this->ajax()) {
            $str = '';
            foreach ($errors as $key => $item) {
                $str .= $key . ':' . implode(',', $item) . '<br>';
            }
            return response()->json([
                'error' => $str
            ]);
        }
        return parent::response($errors);
    }

}
